package org.example.stopthreads;

/**
 * 循环里面使用阻塞方法，相当阻塞方法是 Thread.currentThread().isInterrupted(); 判断是否停止线程
 * 例如 Thread.sleep方法
 */
public class RightWayStopThreadWithSleepEveryLoop {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            int num = 0;
            try {
                while (num <= Integer.MAX_VALUE) {
                    if (num % 100 == 0) {
                        System.out.println("进去了");
                        Thread.sleep(1);
                        System.out.println(num);
                    }
                    num++;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();
        thread.interrupt();
    }
}
